package com.bdbit.ChargingStation.Enum;

public enum OrderStatus {
    UNPAID(0, "未支付"),
    PAID(1, "已支付"),
    CHARGING(2, "充电中"),
    COMPLETED(3, "充电完成"),
    REFUNDED(4, "已退款"),
    TIMEOUT(5, "超时"),
    CANCELLED(6, "已取消");

    private final int code;
    private final String description;

    OrderStatus(int code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * 获取状态代码
     * @return 状态代码
     */
    public int getCode() {
        return code;
    }

    /**
     * 获取状态描述
     * @return 状态描述
     */
    public String getDescription() {
        return description;
    }

    /**
     * 根据状态代码获取对应的枚举值
     * @param code 状态代码
     * @return 对应的订单状态枚举
     * @throws IllegalArgumentException 如果代码无效
     */
    public static OrderStatus fromCode(int code) {
        for (OrderStatus status : values()) {
            if (status.code == code) {
                return status;
            }
        }
        throw new IllegalArgumentException("无效的订单状态代码: " + code);
    }

    /**
     * 根据状态描述获取对应的枚举值
     * @param description 状态描述
     * @return 对应的订单状态枚举
     * @throws IllegalArgumentException 如果描述无效
     */
    public static OrderStatus fromDescription(String description) {
        for (OrderStatus status : values()) {
            if (status.description.equals(description)) {
                return status;
            }
        }
        throw new IllegalArgumentException("无效的订单状态描述: " + description);
    }

    @Override
    public String toString() {
        return this.description;
    }
}
